// Author: wsfuyibing <682805@qq.com>
// Date: 2025-05-15

package info

import (
	"context"
	"gitee.com/go-libs/result"
	"gitee.com/go-libs/validator-iris/validator"
	"gitee.com/go-wares/framework-iris/framework/src/logics"
	"github.com/kataras/iris/v12"
	"server/app/errs"
	"server/app/http/models"
	"server/app/http/services"
	"server/app/lib"
)

// Logic
// 钓位详情.
type Logic struct {
	admin  *models.ArcadeAdmins
	arcade *models.Arcades

	request  *Request
	response *Response
}

// New
// 创建逻辑实例.
func New() logics.Logical {
	return &Logic{
		request:  &Request{},
		response: NewResponse(),
	}
}

// Before
// 前置校验.
func (o *Logic) Before(_ context.Context, i iris.Context) (err error) {
	if err = validator.Query(i, o.request); err == nil {
		o.arcade, o.admin = lib.Arcade.GetMaster().GetArcade(i)
	}
	return
}

// Run
// 执行逻辑.
func (o *Logic) Run(ctx context.Context, _ iris.Context) result.Result {
	var (
		err   error
		has   bool
		res   = result.New()
		model *models.ArcadePond
	)

	if model, has, err = services.NewArcadePondService().Dao.GetById(ctx, o.request.Id); err != nil {
		return res.WithError(errs.ErrDatabaseQuery)
	} else if !has || model.ArcadeId != o.arcade.Id {
		return res.WithError(errs.ErrArcadePondNotFound)
	}

	return res.WithList(o.response.With(model))
}
